Skip to content

Use Contents API instead of raw endpoint to fetch file content#1998

Merged
almaleksia merged 5 commits intomainfrom
almaleksia/get-file-contents-deprecate-raw-endpoint
Feb 12, 2026
Merged

Use Contents API instead of raw endpoint to fetch file content#1998
almaleksia merged 5 commits intomainfrom
almaleksia/get-file-contents-deprecate-raw-endpoint

Conversation

@almaleksia
Copy link
Contributor

Summary

Moving get_file_contents to use Contents API for file content and removing usage of raw endpoint. The latter is flaky - it doesn't support all authentication form GitHub offers, which often result in failures.

Previous logic:

  1. Fetch metadata from Contents API
  2. Fetch content from raw endpoint

New logic:

  1. Fetch metadata from Contents API
  2. If file is less than 1mb - we just take the file content from Contents API response
  3. If the file is bigger than 1mb - we return ResourceLink for the MCP hosts that support them and text with downloadURL that hints LLM to use it for fetching the file.

MIME type is derived from the content of a file.

Why

Fixes #

What changed

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

Prompts tested (tool changes only)

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Note: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Not needed
  • Updated (README / docs / examples)

@almaleksia almaleksia requested a review from a team as a code owner February 11, 2026 16:41
Copilot AI review requested due to automatic review settings February 11, 2026 16:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates get_file_contents to avoid the flaky raw content endpoint by relying on the GitHub Contents API for file retrieval, and returning an MCP ResourceLink for large files.

Changes:

  • Switch get_file_contents to use Contents API content directly for files < 1MB, and return a ResourceLink (plus download URL hint) for larger files.
  • Add a NewToolResultResourceLink helper for returning tool results that include a ResourceLink.
  • Add expandRepoResourceURI to generate consistent repo://... URIs across sha/ref cases, and update tests to cover the new behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/utils/result.go Adds NewToolResultResourceLink helper to return a text message + ResourceLink in tool results.
pkg/github/repository_resource.go Introduces expandRepoResourceURI helper for building repo:// URIs via templates for sha/ref/default.
pkg/github/repositories.go Updates GetFileContents to stop using the raw endpoint, detect MIME from content, and return ResourceLink for large files.
pkg/github/repositories_test.go Updates mocks/expectations for Contents API base64 content, MIME detection, and adds a large-file ResourceLink test.

JoannaaKL
JoannaaKL previously approved these changes Feb 12, 2026
@almaleksia almaleksia merged commit 09d38df into main Feb 12, 2026
16 checks passed
@almaleksia almaleksia deleted the almaleksia/get-file-contents-deprecate-raw-endpoint branch February 12, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants